<?php
declare (strict_types = 1);

namespace app\middleware;

use http\Client\Curl\User;
use think\facade\Cookie;
use app\model\User as UserModel;
class CheckRememberMe
{
    /**
     * 处理请求
     *
     * @param \think\Request $request
     * @param \Closure       $next
     * @return Response
     */
    public function handle($request, \Closure $next)
    {
        //前置中间件
        if(!session('?user')){
            $user_id = Cookie::get('user_id');//保持登录状态
            if($user_id){
                $session_user = UserModel::find($user_id);
                $userArr=$session_user->toArray();
                $userArr['avatar']=$session_user->avatar;
                session('user',$userArr);
            }
        }
        return $next($request);
    }
}
